<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page isErrorPage="true" %>
<%@page import="java.text.SimpleDateFormat"%>
<%@page isErrorPage="true" %>
<%@ page import="java.io.*"%>
	<%    
	response.setStatus(HttpServletResponse.SC_OK);
	%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
  <title>错误页面 </title>
  
	<script src="<%=request.getContextPath()%>/fare/js/jquery-1.6.4.min.js" type="text/javascript"></script>
	<script>            
		function showErrorMessage(){                
			$("#errorMessageDiv").toggle();            
		}            
		$(document).ready(showErrorMessage);       
	</script>
<style type="text/css">
<!--
.t {
        font-family: Verdana, Arial, Helvetica, sans-serif;
        color: #CC0000;
}
.c {
        
        font-size: 15px;
        font-weight: normal;
        color: #000000;
        text-align: center;
        border: 1px solid #CCCCCC;
        background-color: #FFFFEC;
}

-->
</style>
 </head>

 <body>
  <div align="center">         
            
 
			<br /><h2>尊敬的用户,对不起!</h2><h2><span class="t">您所访问的页面出现了异常，请重试. </span></h2>                 
			<br /><h2><span class="c">The pages you visit exception occurred, please try again.</span></h2>
			<br /><br />
					<a id="showErrorMessageButton" href="javascript:showErrorMessage();">详细错误信息</a>
  
  </div>        
  <div id="errorMessageDiv" >           
  <pre>                
		<%                    
		try { 
		             //全部内容先写到内存，然后分别从两个输出流再输出到页面和文件                       
		            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
					PrintStream printStream = new PrintStream(byteArrayOutputStream);                       
					printStream.println();                        
				//	printStream.println("用户信息:");					
				//	printStream.println("用户名：" + request.getSession().getAttribute("userName")); 
					printStream.println("当前访问路径:");                        
					printStream.println(request.getAttribute("javax.servlet.forward.request_uri"));
					printStream.println();  
					printStream.println("异常信息:");                        
					printStream.println(exception.getClass() + " : " + exception.getMessage());                        
					printStream.println();                       
					Enumeration<String> e = request.getParameterNames();                        
					if (e.hasMoreElements()) {                            
						printStream.println("请求中的Parameter包括：");                            
						while (e.hasMoreElements()) {                                
							String key = e.nextElement();                                
							printStream.println(key + "=" + request.getParameter(key));                          
						 }                           
						printStream.println();                       
					}                        
							printStream.println("堆栈信息:");                        
							exception.printStackTrace(printStream);                        
							printStream.println();                        
							out.print(byteArrayOutputStream);    
							//输出到网页                       
							File dir = new File(request.getRealPath("/errorLog"));                        
							if (!dir.exists()) {                            
								dir.mkdir();                        }                        
							String timeStamp = new SimpleDateFormat("yyyyMMddhhmmssS").format(new Date());                        
							FileOutputStream fileOutputStream = new FileOutputStream(new File(dir.getAbsolutePath() + File.separatorChar + "error-" + timeStamp + ".txt"));                        
							new PrintStream(fileOutputStream).print(byteArrayOutputStream); //写到文件                    
							} catch (Exception ex) {                        
								ex.printStackTrace();                    
								}               
		%>           
		</pre>       
		</div>

 </body>
</html>
